/*
 * (c) Copyright Microsoft Corporation. 
 * This source is subject to the Microsoft Public License.
 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL       
 */
package com.microsoft.hsg.util;

import java.util.Map;
import java.util.TreeMap;


/**
 * The Class EnumCodeLookup.
 */
public class EnumCodeLookup<T extends Enum<T> & EnumCode > {

	private Map<Integer, T> map = new TreeMap<Integer, T>();
	
	/**
	 * Instantiates a new enum code lookup.
	 * 
	 * @param clazz the clazz
	 */
	public EnumCodeLookup(Class<T> clazz) {
		for (T t : clazz.getEnumConstants()) {
			map.put(t.getCode(), t);
		}
	}

	/**
	 * Gets the.
	 * 
	 * @param code the code
	 * 
	 * @return the t
	 */
	public T get(int code) {
		return map.get(code);
	}
}
